﻿#region File Description
// --------------------------------
// <copyright file="SoundEffectsPlayer.cs" company="Faculty of Information Technology, Czech Technical University in Prague">
//     This document is shared by Microsoft Public License (MS-PL)
//     For further details please see http://msdn.microsoft.com/en-us/library/ff648068.aspx or license.txt.
// </copyright>
// <author>Vladislav Richter</author>

// <email>richtvl2@fit.cvut.cz</email>

// <date>9. 11. 2011 22:22:37</date>

// <summary>
// 
// </summary>
// ------------------------------------------------------------------------------------------------------
#endregion
using System;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;

namespace ExternalClasses.Sounds
{
    public class SoundEffectsPlayer
    {
        AudioListener audioListener;
        SoundEffectsCollection SoundCollection;
        public bool Muted { get; set; }

        public SoundEffectsPlayer(SoundEffectsCollection collection, Vector3 position)
        {
            this.SoundCollection = collection;
            this.audioListener = new AudioListener();
            this.audioListener.Position = position;
            //this.PunhcSoundEffect = 
        }

        public void PlaySoundEffect(string name, Vector2 position)
        {
            if (Muted == true) return;
            if (!this.SoundCollection.Effects.ContainsKey(name))
            {
                Console.WriteLine("ERROR: SoundEffect {0} does not exist!!!", name);
                return;
            }
            
            SoundEffectInstance soundEffectInstance = this.SoundCollection.Effects[name].CreateInstance();
            AudioEmitter audioEmitter = new AudioEmitter();            
            audioEmitter.Position = new Vector3(position,0);
            soundEffectInstance.Apply3D(audioListener, audioEmitter);
            soundEffectInstance.IsLooped = false;
            soundEffectInstance.Play();
        }
    }
}
